//
//  adduserViewController.m
//  table
//
//  Created by iD Student on 7/11/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "adduserViewController.h"

@interface adduserViewController ()

@end

@implementation adduserViewController
@synthesize namefield;
@synthesize aboutfield;
@synthesize statusfield;
@synthesize addButton;
@synthesize listbutton;
@synthesize tableview;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    tableview=[self.storyboard instantiateViewControllerWithIdentifier:@"tableview"];
    
    
    tableview.List_of_Friends=[[NSMutableArray alloc] init];

    
    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setNamefield:nil];
    [self setAboutfield:nil];
    [self setStatusfield:nil];
    [self setAddButton:nil];
    [self setListbutton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)listButton:(id)sender {
    [self presentModalViewController:tableview animated:YES];
}


-(IBAction)add:(id)sender{
    
    if ([namefield.text isEqualToString:@""]){
        UIAlertView *x =[[UIAlertView alloc] initWithTitle:@"Error" message:@"Fill in all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [x show];
    }

    else {
        user *usr = [[user alloc]init];
        usr.name= namefield.text;
        usr.aboutMe = aboutfield.text;
        usr.status= statusfield.text;
        
        [tableview.List_of_Friends addObject:usr];


        

        
        
        

        //create a user
        //add the user to the list of friends of the table view
    } 
}

    
@end
